home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat38 / viewer / sources / viewer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-30  |  17.9 KB  |  848 lines

  1. /*
  2. //
  3. //      Viewer
  4. //
  5. //
  6. //
  7. //  Rodrigo REYES 1993
  8. //
  9. //  freeware
  10. //
  11. //
  12. // Lors de la compilation, ce fichier devra être linké au fichier
  13. // objet DSIC.o.
  14. //
  15. // 
  16. //
  17.  
  18. //
  19. // Les includes suivants sont ceux du système 3.0.
  20. */
  21.  
  22. #include <exec/types.h>
  23. #include <stdio.h>
  24.  
  25. #include <Dsic.h>      /*   Protos du module de gestion dynamique   */
  26.                        /*   des chaines.  Bientôt disponible en DP  */
  27.  
  28. #include <proto/dos.h>
  29. #include <dos/dosasl.h>
  30. #include <workbench/workbench.h>
  31. #include <workbench/startup.h>
  32. #include <workbench/icon.h>
  33. #include <proto/icon.h>
  34. #include <libraries/dosextens.h>
  35.  
  36. #include <proto/exec.h>
  37. #include <intuition/screens.h>
  38. #include <pragmas/intuition_pragmas.h>
  39. #include <proto/graphics.h>
  40. #include <graphics/modeid.h>
  41. #include <proto/gadtools.h>
  42.  
  43. struct IntuitionBase *IntuitionBase;
  44.  
  45. #include "display.c"    /*  source fourni par GadToolsBox 1.4   */
  46.  
  47. #include <exec/ports.h>
  48. #include <intuition/intuition.h>
  49.  
  50. #include <clib/dos_protos.h>
  51. #include <exec/libraries.h>
  52. #include <libraries/asl.h>
  53. #include <clib/exec_protos.h>
  54. #include <clib/asl_protos.h>
  55.  
  56. #include "FileSize.c"      /* module permettant de savoir la  */
  57.                            /* taille d'un fichier             */
  58.  
  59.  
  60. /*------------------------- Les variables globales ------------------*/
  61.  
  62. #define MODE_NIL 2
  63. #define MODE_CLI 1
  64. #define MODE_WB 0
  65.  
  66.  
  67.     int QuietMode=0;
  68.     int delay=-1;
  69.     
  70.     char *TheName;
  71.  
  72.     struct Library *AslBase = NULL;
  73.     struct FileRequester *fr;    
  74.     
  75.     char Name[256],comp,mod;
  76.     long MemBlock,BlockSize;       /* block de mémoire pour l'image */
  77.     short sX,sY,sD;
  78.     int MODE;
  79.     int cyc1=0,cyc2=0;        /* les options d'affichage             */
  80.                               /*      cyc1 = 0 : default             */
  81.                          /*      cyc1 = 1 : LoRes               */
  82.                          /*      cyc1 = 2 : HiRes               */
  83.                          /*      cyc1 = 3 : SuperHiRes          */
  84.                          
  85.                          /*      cyc2 = 0 : default             */
  86.                          /*      cyc2 = 1 : Lace                */
  87.                          /*      cyc2 = 2 : NoLace              */
  88.                          
  89.                          /* Correspondant au Cycling Gadget     */
  90.                          
  91.     int LOADED=0;  /* flag permettant de savoir si l'image est chargée */
  92.     
  93.     UWORD Mask[]= {1,2,4,8,16,32,64,128,256};
  94.                 /* nombre de couleurs par bitplans  */
  95.                 
  96.  
  97. /*--------------- See you later, proto ? -------------*/
  98.  
  99.  
  100. void DoCli(int, char **);        /* si chargé par le CLI  */
  101. void ProceedWithFile(char *);      /* Charger et afficher le fichier */
  102. void DoWB(struct WBStartup *);     /* si chargé par le WB   */
  103.  
  104. void Set2Zero(void);       /* RAZ des paramètres  */
  105.  
  106. void DoPannel(void);       /* affiche et gère le panneau de contrôle  */
  107.  
  108. void OpenLibs(void);
  109. void CloseLibs(void);
  110.  
  111. void GetMemFile(char *);    /* allocation et chargement du nom de fichier */
  112. void DropFileMem(void);    /* désallocation de la mémoire allouée   */
  113. int Search(char *);       /* routine de recherche de chaine dans MemBlock */
  114. void LookILBM(void);     /* Affichage de l'image ILBM  */
  115. void ReadBody(struct Screen *);   /* Affichage du corps de l'image */
  116.  
  117. void LoadOneFile(void);        /*    gestion du requester   */
  118.  
  119. void RendCycle(struct Gadget *,long );   /* gestion des cycling gadgets */
  120.  
  121. char GetFile(char *,int);     /* affiche le requester   */
  122. void InitReq(char *);         /* initialise le requester */
  123. void FreeReq(void);           /* libère le requester    */
  124.  
  125. void Print(int ,int ,char *);  /* bête routine d'affichage */
  126. void PrintInfo(void);          /* affichage des infos sur le fichier ILBM */
  127. void Clear(void);             /*  nettoie la fenêtre d'affichage des info */
  128. void WaitClick(void);      /* attend un click ou un delay   */
  129.  
  130.  
  131. /*------------------ Routines Principales ---------------*/
  132.  
  133. void main(int ArgC, char *ArgV[])
  134. {
  135.     if ( ArgC == 1 ) DoPannel();        //  Help ?
  136.     if ( ArgC > 1 ) DoCli(ArgC, (char **)ArgV);        // It came from the CLI
  137.     if (ArgC==0) DoWB((struct WBStartup *)ArgV);        // It came from the workbench
  138.     return;
  139. }
  140.  
  141.  
  142.  
  143.  
  144. /*------------------- APPEL PAR LE CLI -----------------*/
  145.  
  146. void DoCli(int Count, char *args[])
  147. {
  148.     short j;
  149.     long Membloq;
  150.     struct AnchorPath *ap;
  151.     long loq;    
  152.     
  153.     MODE = MODE_CLI;
  154.  
  155.     OpenLibs();
  156.  
  157.     /*-------------------- Analyse des arguments ------------------------*/
  158.  
  159.     for (j=1; j<Count; j++)
  160.     {
  161.         if (StringCompNC("LACE",args[j])) cyc2=1;
  162.     else        if (StringCompNC("NOLACE",args[j])) cyc2=2;
  163.     else    if (StringCompNC("LORES",args[j]))  cyc1=1;
  164.     else    if (StringCompNC("HIRES",args[j])) cyc1=2;
  165.     else    if (StringCompNC("SHIRES",args[j])) cyc1=3;
  166.     else if (StringCompNC("QUIET",args[j])) QuietMode=1;
  167.     else if (StringCompNC("DELAY",args[j]) && j<(Count-1)) delay = StringVal(args[++j]);
  168.     else if (StringCompNC("FILE",args[j]) && j<(Count-1)) TheName = args[++j];
  169.     else if (!TheName) TheName = args[j];
  170.  
  171.     }
  172.  
  173.     if (TheName==0) { CloseLibs(); return;}
  174.  
  175.  
  176.     /* ------------ Allocation du AnchorPath, pour les Patterns ----*/
  177.  
  178.     Membloq = (long) AllocMem( sizeof(struct AnchorPath)+1028,(1<<0+1<<16) );
  179.     
  180.     ap = (struct AnchorPath *)((Membloq+3)&0xfffffff0);
  181.     ap->ap_Strlen = 1024;
  182.     
  183.     
  184.     /* --------------- traitement des fichiers ----------------- */
  185.     
  186.     if ( loq = Lock(TheName,-2) )       /* si c'est un simple fichier */
  187.             {    
  188.                 ProceedWithFile(TheName);
  189.                 UnLock(loq);
  190.             }
  191.             
  192.     else if ( MatchFirst(TheName,ap) ==0)    /* si c'est un motif  */
  193.             {
  194.                 while ( MatchNext(ap) == 0)   /* les faire tous  */
  195.                     {
  196.                     if (ap->ap_Info.fib_DirEntryType<0 && StringIndexNC(".info",ap->ap_Buf)==0)
  197.                             ProceedWithFile(ap->ap_Buf);
  198.                     }
  199.             MatchEnd(ap);
  200.             }
  201.  
  202.         else if (!QuietMode)printf("Pattern not found!\n");
  203.  
  204.  
  205.     /* ------------ la fin ... --------------- */
  206.  
  207.     FreeMem((APTR)Membloq, sizeof(struct AnchorPath)+1028 );
  208.     CloseLibs();
  209. }
  210.  
  211. /* ----------- Mise en Oeuvre de la machinerie ------------- */
  212.  
  213. void ProceedWithFile(char *file)
  214. {
  215.     Print(0,0,"File : ");
  216.     Print(0,0,file);
  217.     Print(0,0,"\n");
  218.     GetMemFile(file);
  219.     PrintInfo();
  220.     LookILBM();
  221.     DropFileMem();
  222.     Print(0,0,"\n");
  223.     return;
  224. }
  225.  
  226. /*------------------ SI DES FICHIERS SONT APPELES VIA LE WB ----*/
  227.  
  228. void DoWB(struct WBStartup *wbstart)
  229. {
  230.     short i;
  231.     long olddir,Tools,curval;
  232.     struct DiskObject *Loq;
  233.     struct WBArg *wbarg;
  234.     char onename[512];
  235.     
  236.     MODE= MODE_CLI;
  237.  
  238.     OpenLibs();
  239.     
  240.     if ( !(IconBase = OpenLibrary("icon.library",0))) return;
  241.     if (wbstart==0) { CloseLibrary(IconBase); CloseLibs(); return; }
  242.     
  243.     if (wbstart->sm_NumArgs==1) DoPannel();   /* si on clique sur VIEWER /*
  244.     else
  245.     
  246.             /* ALORS POUR CHAQUE ARGUMENT */
  247.     
  248.     for (i=1,wbarg = (wbstart->sm_ArgList)+1; i<wbstart->sm_NumArgs ;i++, wbarg++)
  249.         {
  250.             Set2Zero();
  251.             
  252.             olddir = CurrentDir(wbarg->wa_Lock);
  253.             Loq = GetDiskObject(wbarg->wa_Name);
  254.  
  255.             if (Loq)     /* si le fichier existe (on ne sait jamais...) */
  256.             {
  257.                 NameFromLock(wbarg->wa_Lock,onename,512);
  258.                 AddPart(onename,wbarg->wa_Name,512);
  259.                 
  260.                 Tools = (long) Loq->do_ToolTypes;
  261.  
  262.                 if (FindToolType((UBYTE **)Tools,"LORES")) cyc1=1;
  263.                 if (FindToolType( (UBYTE **)Tools,"HIRES")) cyc1=2;
  264.                 if (FindToolType((UBYTE **)Tools,"SHIRES")) cyc1=3;
  265.                 if (FindToolType((UBYTE **)Tools,"LACE")) cyc2=1;
  266.                 if (FindToolType((UBYTE **)Tools,"NOLACE")) cyc2=2;
  267.                 if (curval = (long) FindToolType((UBYTE **)Tools,"DELAY"))
  268.                              delay = (StringVal( (char *)curval));
  269.                                 
  270.                 FreeDiskObject(Loq);
  271.  
  272.                 GetMemFile(onename);
  273.                 LookILBM();
  274.                 DropFileMem();
  275.  
  276.             }
  277.             CurrentDir(olddir);
  278.  
  279.         }
  280.         
  281.     CloseLibrary(IconBase);
  282.     CloseLibs();
  283. }    
  284.  
  285. /*------------------- RAZ des paramètres d'affichages ------------*/
  286. void Set2Zero()
  287. {
  288.     cyc1=0;
  289.     cyc2=0;
  290.     delay = -1;
  291. }
  292.  
  293. /*---------------------- Les Autres ROUTINES  -----------*/
  294.  
  295.  
  296. /*--------------Affiche le superbe :-) panneau de contrôle --*/
  297.  
  298. void DoPannel()
  299. {
  300.     short back=1,norem;
  301.     struct StringInfo *strinf;
  302.     struct IntuiMessage *msg;
  303.     struct Gadget *gad;
  304.     ULONG class;    
  305.     
  306.     OpenLibs();            
  307.  
  308.     /*------------------- mise en place de la fenètre ----------- */
  309.  
  310.     SetupScreen();
  311.     OpenILBMViewerWindow();
  312.     ILBMViewerRender();
  313.     
  314.     InitReq("Please select an iff-ilbm file");  /* init du requester */
  315.     
  316.     MODE = MODE_WB;
  317.  
  318.     while(back)    /* TANT QUE pas fini  */
  319.     {
  320.         msg = (struct IntuiMessage *)WaitPort(ILBMViewerWnd->UserPort);
  321.         msg = (struct IntuiMessage *)GetMsg(ILBMViewerWnd->UserPort);
  322.         class = msg->Class;
  323.         
  324.         if (class == IDCMP_GADGETUP)
  325.         {
  326.             gad = (struct Gadget *)msg->IAddress;
  327.             if (gad->GadgetID == GD_FWGadget)
  328.                 {
  329.                     ++cyc1;
  330.                     if (cyc1>3) cyc1=0;
  331.                     RendCycle(gad,cyc1);
  332.                                         /*   FORCEGADGET  */
  333.                 }
  334.             if (gad->GadgetID == GD_FHGadget)
  335.                 {
  336.                     ++cyc2;
  337.                     if (cyc2>2) cyc2=0;
  338.                     RendCycle(gad,cyc2);
  339.                                         /* FORCEGADGET   */
  340.                 }
  341.  
  342.             if (gad->GadgetID == GD_LoadGadget)
  343.                     LoadOneFile();            /* Appel du REQUESTER */
  344.  
  345.             if (gad->GadgetID == GD_ShowGadget)
  346.                     LookILBM();             /* AFFICHAGE   */
  347.  
  348.             if (gad->GadgetID == GD_StringGadget)
  349.                     {    DropFileMem();
  350.                         strinf = (struct StringInfo *)gad->SpecialInfo;
  351.                         GetMemFile((char *) strinf->Buffer);
  352.                         PrintInfo();
  353.                     }
  354.         }
  355.         if (class == IDCMP_CLOSEWINDOW)
  356.             back = 0;
  357.                 
  358.         ReplyMsg( (struct Message *) msg);
  359.         
  360.  
  361.         
  362.     /* ------ Met au vide-ordure tous les messages en trop  ------- */
  363.         
  364.         norem=1;
  365.         while (norem)
  366.         {    msg = (struct IntuiMessage *)GetMsg(ILBMViewerWnd->UserPort);
  367.             if (msg) ReplyMsg( (struct Message *)msg);
  368.             else norem=0;
  369.         }
  370.     }
  371.     DropFileMem();
  372.  
  373.     CloseILBMViewerWindow();
  374.     CloseDownScreen();
  375.     
  376.     FreeReq();
  377.     
  378.     CloseLibs();
  379.  
  380. }
  381.  
  382.     /* ------------------ Ouvre toutes les bibliothèques ------ */
  383.  
  384. void OpenLibs()
  385. {
  386.     IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  387.     DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0);
  388.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  389.     AslBase = OpenLibrary("asl.library",37l);
  390.     GadToolsBase = OpenLibrary("gadtools.library",0);
  391.     StringBufferInit(10000);
  392.  
  393. }
  394.     
  395.     /* ---------------- Ferme toutes les bibliothèques --------- */
  396.  
  397. void CloseLibs()
  398. {
  399.     if (GfxBase) CloseLibrary( (struct Library *) GfxBase);
  400.     if (IntuitionBase) CloseLibrary( (struct Library *) IntuitionBase);
  401.     if (DOSBase) CloseLibrary( (struct Library *) DOSBase);
  402.     if (AslBase) CloseLibrary( (struct Library *) AslBase);
  403.     if (GadToolsBase) CloseLibrary(GadToolsBase);
  404.     StringBufferEnd();
  405. }
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.     /* ------------------- Gère le cycling gadget ---------------- */
  413.  
  414. void RendCycle(struct Gadget *gd,long cyc)
  415. {
  416.     GT_SetGadgetAttrs(gd,ILBMViewerWnd,0,GTCY_Active,(ULONG) cyc,TAG_DONE);
  417.     GT_RefreshWindow(ILBMViewerWnd,0);
  418.     
  419. }
  420.  
  421.  
  422.  
  423.  
  424.     /* -------------- Chargement d'un FICHIER --------------*/
  425.  
  426. void LoadOneFile()
  427. {
  428.     int dummy,d1;
  429.     char *c;
  430.     struct StringInfo *ST;
  431.     
  432.     char *file,*cd,*ct;
  433.     
  434.  
  435.     //    APPEL DU REQUESTER
  436.     //
  437.     ST = (struct StringInfo *)ILBMViewerGadgets[GDX_StringGadget]->SpecialInfo;
  438.     c= ST->Buffer;
  439.     file = FilePart(c);
  440.     ct = (char *)fr->fr_File;
  441.     cd = file;
  442.     while (*cd) *ct++=*cd++;  *ct=0;
  443.     
  444.     ct = (char *)fr->fr_Drawer;
  445.     cd=c;
  446.     file = PathPart(c);
  447.     while (cd<file) *ct++ = *cd++; *ct=0;
  448.  
  449.     for (d1=0; d1<255; d1++) Name[d1]=*c++;    
  450.     dummy = GetFile(Name,255);
  451.     
  452.     //  SI UN FICHIER EST CHOISI
  453.     //
  454.     if (dummy)
  455.     {
  456.         //
  457.         // COPIE
  458.         //
  459.         ST = (struct StringInfo *)ILBMViewerGadgets[GDX_StringGadget]->SpecialInfo;
  460.         c= ST->Buffer;
  461.         for(d1=0; d1<255; d1++) *c++=Name[d1];
  462.         
  463.         RefreshGadgets(ILBMViewerGadgets[0],ILBMViewerWnd,0);
  464.         
  465.         DropFileMem();        
  466.         GetMemFile((char *)&Name);
  467.         
  468.         //    ILBM ??
  469.         //
  470.         d1 = Search("ILBM");
  471.         if (d1!=-1)  { LOADED=1; PrintInfo();}
  472.         
  473.     }
  474. }
  475.  
  476.  
  477.  
  478.  
  479.  
  480.     /* ---  RESERVATION DE LA MEMOIRE ET CHARGEMENT DU FICHIER ---- */
  481.  
  482. void GetMemFile(char *File)
  483. {
  484.     int size;
  485.     struct FileHandle *handle;
  486.     
  487.     MemBlock=0;
  488.     size = FileSize(File);
  489.     if (size)
  490.     {
  491.         BlockSize = size;
  492.         MemBlock = (long)AllocMem(size,1l<<16);
  493.         handle = (struct FileHandle *)Open(File,1005);
  494.         Read((BPTR)handle,(APTR)MemBlock,size);
  495.         Close((BPTR)handle);
  496.         return;
  497.     }
  498. }
  499.  
  500.  
  501.     /*------------- REND LA MEMOIRE --------------------*/
  502.  
  503. void DropFileMem()
  504. {
  505.     if (MemBlock)
  506.     {
  507.         FreeMem((APTR)MemBlock,BlockSize);
  508.     }
  509.     MemBlock=0;
  510.     
  511. }
  512.  
  513.  
  514.     /* ---------- FONCTION DE RECHERCHE D'UNE CHAINE ------- */
  515.  
  516. int Search(char *String)
  517. {
  518.     int size;
  519.     char *dum;
  520.     char *Start,*SD;
  521.     int i=0;
  522.     
  523.     size=0; dum=String;
  524.     while(*dum++) ++size;
  525.  
  526.     for (Start=(char *)MemBlock ; (long)Start<=(MemBlock+BlockSize); )
  527.     {
  528.         if (*Start==*String)
  529.         {
  530.             SD=Start;
  531.             for (i=0;i<size;)
  532.             {
  533.                 if ( SD[i] != String[i]) break;
  534.                 ++i;
  535.             }
  536.             if (i==size)       return((int)Start);
  537.         }    
  538.     ++Start;
  539.     }
  540.     return(0);
  541. }
  542.  
  543.  
  544.     /* --------  INFOS sur l'image -----------------*/
  545.  
  546. void PrintInfo()
  547. {
  548.     char *c1,*c2,*c3;
  549.     UWORD *T;
  550.     T = (UWORD *)Search("BMHD");
  551.     if (MODE == MODE_WB) Clear();
  552.     if (MemBlock)
  553.     {
  554.     if ((int)T!=0)
  555.     {
  556.         sX=T[4]; sY=T[5];
  557.         sD=T[8]>>8;
  558.         comp=T[9]>>8;
  559.         
  560.         c1 = StringDec(sX);
  561.         c2 = StringDec(sY);
  562.         c3 = StringAdd("IFF Picture ",c1);
  563.         c3 = StringUnion(c3,"x");
  564.         c3 = StringUnion(c3,c2);
  565.         Print(0,0,c3);
  566.         StringDelete(c1); StringDelete(c2); StringDelete(c3);
  567.         
  568.         T = (UWORD *) (Search("CAMG")+8);
  569.         c1 = StringDec(sD);
  570.         c2 = StringAdd("Depth : ",c1);
  571.         c2=StringUnion(c2,"  ");
  572.         if (T)
  573.         {
  574.             if (T[1]&HAM) c2=StringUnion(c2,"HAM ");
  575.             if (T[1]&LACE) c2=StringUnion(c2,"LACE ");
  576.             if (T[1]&SUPERHIRES) c2=StringUnion(c2,"SUPERHIRES");
  577.             if (T[1]&HIRES) c2=StringUnion(c2,"HIRES ");
  578.         }     
  579.         Print(0,8,c2);
  580.         StringDelete(c1); StringDelete(c2);
  581.  
  582.     }
  583.     else Print(0,0,"File is not an IFF picture!");    
  584.     }
  585.     else Print(0,0,"No file Loaded");
  586.     
  587. }
  588.  
  589.  
  590.     /* ----------  ANALYSE et AFFICHAGE DU FICHIER ILBM -------- */
  591.  
  592. void LookILBM()
  593. {
  594.     struct Screen *screen;
  595.     UWORD *T;
  596.     ULONG dispID;
  597.     short j;
  598.     unsigned char *ccol;
  599.     ULONG *colortable;
  600.  
  601.     T = (UWORD *)Search("BMHD");
  602.     if ((int)T!=0 && MemBlock)
  603.     {
  604.         sX=T[4]; sY=T[5];
  605.         sD=T[8]>>8;
  606.  
  607.         if (sD>8) {
  608.                     Print(0,18,"Can't display so many bitplanes !");
  609.                     return;
  610.                 }
  611.                 
  612.         comp=T[9]>>8;
  613.         
  614.         mod = T[4]%8;
  615.         
  616.         dispID = LORES_KEY;
  617.         if (sY>320)
  618.         {
  619.             if (sX>320 && sX<870) dispID=HIRESLACE_KEY;
  620.             if (sX>869) dispID=SUPERLACE_KEY;
  621.             if (sX<321) dispID=LORESLACE_KEY;
  622.         }
  623.         else
  624.         {    if (sX>320 && sX<870) dispID=HIRES_KEY;
  625.             if (sX>869) dispID=SUPER_KEY;
  626.         }
  627.  
  628.         T = (UWORD *) (Search("CAMG")+8);
  629.          if (T[1]& HAM) dispID|=HAM_KEY;
  630.         if (T[1]& LACE) dispID|=LACE;
  631.         if (T[1]& EXTRA_HALFBRITE)  dispID |=EXTRA_HALFBRITE;
  632.         if (T[1]& HIRES ) dispID |= HIRES;
  633.         
  634.         if (cyc1==1) dispID = dispID & (0xffffffff-HIRES-SUPERHIRES);
  635.         if (cyc1==2) dispID = (dispID & (0xffffffff-SUPERHIRES-HIRES))+HIRES;
  636.         if (cyc1==3) dispID = (dispID & (0xffffffff-HIRES-SUPERHIRES))+SUPERHIRES+HIRES;
  637.         
  638.         if (cyc2==1) dispID |= LACE;
  639.         if (cyc2==2) dispID &= (0xffffffff-LACE);
  640.         
  641.         colortable = AllocMem(4+(3*4*256),1<<0+1<<16);
  642.         
  643.         ccol = (char *)(Search("CMAP")+8);
  644.         j=0;
  645.         if (ccol)
  646.         {
  647.             colortable[j++]= Mask[sD]<<16;
  648.             for (; j<((Mask[sD]*3)+1);)
  649.             {    colortable[j++]=((*ccol++)<<24)+0xffffff;
  650.                 colortable[j++]=((*ccol++)<<24)+0xffffff;
  651.                 colortable[j++]=((*ccol++)<<24)+0xffffff;
  652.             }
  653.         colortable[j++]=0;
  654.         }    
  655.  
  656.         screen = OpenScreenTags(0,
  657.                     SA_DisplayID, dispID,
  658.                     SA_Left, 0,
  659.                     SA_Top,0,
  660.                     SA_Width, sX,
  661.                     SA_Height, sY,
  662.                     SA_Depth, sD,
  663.                     SA_Type, CUSTOMSCREEN,
  664.                     SA_Colors32, colortable,
  665.                     SA_Title, "ILBM-Viewer",
  666.                     SA_AutoScroll, TRUE,
  667.                     TAG_DONE);
  668.  
  669.         if (screen)        { ReadBody(screen); WaitClick(); }
  670.         else Print(0,16,"Can't display picture !");
  671.         
  672.         if (screen)        CloseScreen(screen);
  673.         if (colortable) FreeMem(colortable,4+(3*4*256));
  674.         
  675.     }
  676. }
  677.  
  678.  
  679.  
  680.  
  681.     /* ------------ LECTURE DU CORPS (BODY) ---------------- */
  682.  
  683. void ReadBody(struct Screen *SC)
  684. {
  685.     int T;
  686.     short modulo;
  687.     unsigned short bp,row;
  688.     register short ddum,ddum1,y;
  689.     char *adr,*ptr,buf;
  690.     unsigned char doumdoum;
  691.     long lim=MemBlock+BlockSize;
  692.     short row2;    
  693.  
  694.     row2=((SC->Width+15)&(0xfff0))>>3;   //  /8
  695.  
  696.     row = SC->BitMap.BytesPerRow;
  697.     
  698.  
  699.     modulo = SC->Width%8;
  700.     
  701.  
  702.     T= Search("BODY");
  703.     ptr = (char *) (T+8);
  704.     if (T!=(int)0)
  705.     {
  706.         for (y=0; y<SC->Height; y++)
  707.         {
  708.         for (bp=0; bp<SC->Depth; bp++)
  709.             {
  710.             adr = (char *) (SC->RastPort.BitMap->Planes[bp]+(y*row));
  711.             
  712.             if (comp==0)
  713.                 for(ddum=0; ddum<row2; ddum++)
  714.                     *adr++ = *ptr++; 
  715.                 
  716.  
  717.             if (comp==1)
  718.             {
  719.                 ddum=0;
  720.                 while (ddum<row2)
  721.                 {
  722.                     doumdoum = *ptr++;
  723.                     if (doumdoum<128)
  724.                         for( ddum1=0; ddum1<=doumdoum; ddum1++,ddum++)
  725.                                 *adr++ = *ptr++;
  726.                     if (doumdoum>128)
  727.                         {
  728.                         buf = *ptr++;
  729.                         for (ddum1=0; ddum1<(257-doumdoum); ddum1++,ddum++)
  730.                             *adr++= buf;
  731.                         }
  732.                     // if (ddum>row) printf("Row dépassé\n");
  733.                 }
  734.             }
  735.             }
  736.             
  737.             if ((int)ptr>lim) return;
  738.  
  739.         }
  740.     }
  741. }
  742.  
  743.  
  744. /*------------------ FONCTIONS DU REQUESTER -------------------- */
  745.  
  746.  
  747. #define MYLEFTEDGE 0
  748. #define MYTOPEDGE  0
  749. #define MYWIDTH    320
  750. #define MYHEIGHT   190
  751.  
  752. void InitReq(char *title)
  753. {
  754.             struct TagItem frtags[] =
  755.     {
  756.         ASL_Hail,       (ULONG) "",
  757.         ASL_Height,     MYHEIGHT,
  758.         ASL_Width,      MYWIDTH,
  759.         ASL_LeftEdge,   MYLEFTEDGE,
  760.         ASL_TopEdge,    MYTOPEDGE,
  761.         ASL_OKText,     (ULONG)"Select",
  762.         ASL_CancelText, (ULONG)"Cancel",
  763.         ASL_File,       (ULONG) "",
  764.         ASL_Dir,        (ULONG) "",
  765.          ASLFR_RejectIcons, (ULONG) 1,
  766.         TAG_DONE
  767.     };
  768.    frtags[0].ti_Data=(ULONG) title;
  769.     if (AslBase)
  770.     fr = (struct FileRequester *) AllocAslRequest(ASL_FileRequest,frtags);
  771.  
  772. }
  773.  
  774. char GetFile(char *buffer,int size)
  775. {
  776.     char *i,*d,tobereturned=0;
  777.     short j;
  778.     
  779.     d=buffer;
  780.     if (AslRequest(fr, NULL))
  781.     {
  782.         i=fr->rf_Dir;
  783.         for (j=0; j<250; j++) buffer[j]=0;
  784.         while (*i) *d++=*i++;
  785.         AddPart(buffer,fr->rf_File,size);
  786.         tobereturned=1;
  787.     }
  788.  
  789.     return(tobereturned);
  790. }
  791.  
  792. void FreeReq()
  793. {
  794.     if (AslBase)
  795.     {
  796.         if (fr) FreeAslRequest(fr);
  797.     }
  798. }
  799.  
  800. /* -------------------- Petite routine d' Affichage de texte ------- */
  801.  
  802. void Print(int x,int y, char *string)
  803. {    short count=0;
  804.     char *c;
  805.  
  806.     if (QuietMode) return;
  807.     
  808.     if (MODE == MODE_WB)
  809.     {
  810.         Move(ILBMViewerWnd->RPort,18+x,56+y);
  811.         c=string;    while (*c++) ++count;
  812.         Text(ILBMViewerWnd->RPort,string,count);
  813.     }
  814.     else printf("%s",string);
  815. }
  816.  
  817.     /* ---------------- Monsieur PROPRE --------------- */
  818.  
  819. void Clear()
  820. {
  821.     SetAPen(ILBMViewerWnd->RPort,0);
  822.     RectFill(ILBMViewerWnd->RPort,12,50,315,78);
  823.     SetAPen(ILBMViewerWnd->RPort,1);
  824. }
  825.  
  826.  
  827.     /* -------------------- Routine d'ATTENTE ------------- */
  828.  
  829. void WaitClick()
  830. {
  831.     short j;
  832.     
  833.     UWORD *RightMouseButton = (UWORD *)0xdff016;
  834.                            /* ON tape direct dans le hard      */
  835.                            /* Oui je sais c'est pas Bô         */   
  836.     
  837.     if (delay == -1)
  838.     while (*RightMouseButton & 0x400) Delay(1);
  839.     else
  840.     for (j=0; j<delay*10; j++)
  841.         {
  842.             Delay(5);
  843.             if ( !(*RightMouseButton & 0x0400)) break;
  844.         }
  845.         
  846. }
  847.  
  848.